<?php

/**
 * Project: Espolon
 * Licence: BSD License
 * Link: http://espolon.org/
 * Copyright: Nicolas de Bari Embriz Garcia Rojas <nbari at espolon dot org>
 * Author: Nicolas de Bari Embriz Garcia Rojas <nbari at espolon dot org>
 * Version: Beta
 */

if (!defined('SITE_ROOT')) exit('No direct script access allowed');

/**
 * Check perms and module status on/off
 */
$this->checkAccess($module, $command);
$tpl->assign('active', $module);
$tpl->assign('menu_active', $command);

foreach ($this->getPerms($module) as $key => $value) {
  if(!in_array($value, array('modify'))) {
    $submenu[] = $value;
  }
}

$tpl->assign('submenu', $submenu);

/**
 * Autoload classes
 */
function __autoload($class_name) {
  require_once 'class.'.strtolower($class_name).'.php';
}

$art = new Article();

switch($command) {
  case 'add':
    $form = new AddArticle($tpl, $art, $db);
    if ($form->validate()) {
      $form->freeze();
      $form->process();
    } else {
      $form->displayForm();
    }
  break;
  default:
  break;
}

/**
 * display module
 */
$tpl->assign('command_tpl',"$template/modules/$module/".((isset($command_tpl)) ? $command_tpl : "$command.tpl"));
$tpl->assign('module_tpl', "modules/$module/$module_tpl");
$tpl->display($template.'/base.tpl');

?>